﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yatagan.BaseAspects;
using System.Reflection;
using Yatagan.IoC.ObjectBuilder;

namespace Yatagan.IoC
{
    [Serializable]
    public class IoCAspect : MethodInvocationAspect
    {
        public override void OnInvocation(MethodInvocationEventArgs eventArgs)
        {
            List<object> newArguments = new List<object>();
            ParameterInfo[] arguments = eventArgs.Delegate.Method.GetParameters();

            foreach (ParameterInfo argument in arguments)
            {
                newArguments.Add(ObjectDirector.Create(argument.ParameterType));
            }

            eventArgs.Delegate.DynamicInvoke(newArguments.ToArray());
        }
    }
}
